﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Net.NetworkInformation;
using System.IO.Ports;
using System.Web;
using System.Security.Policy;


namespace Philadapt
{
    
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// 

        

        [STAThread]
        static void Main()
        {
            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            IPHostEntry host ;
            
            
            
            String server;
            int port = 0;
            
            //sever = System.Environment.GetEnvironmentVariable()
            //host = host.get

            //host =    getCodeBase().getHost();
           // DiscoveryClientProtocol myProtocol = new DiscoveryClientProtocol();

            


            IPAddress urlform1 = System.Net.IPAddress.Loopback;
            server = Dns.GetHostName();
            IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
            String compname = properties.HostName;
            String domname = properties.DomainName;

            try
            {

                host = Dns.GetHostEntry(urlform1);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("address is a null reference (Nothing in Visual Basic). ");
            }
            catch (SocketException e)
            {
                Console.WriteLine("An error is encountered when resolving address");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("address is an invalid IP address.");
            }
            //Url url = new Url(urlform1);
            String url1;
           // url1 = url.Value;
           /* TcpListener tcpListener = new TcpListener(10);
            tcpListener.Start();

            //while (true)
            //{
                Socket socketForClient = tcpListener.AcceptSocket();
                NetworkStream networkStream = new NetworkStream(socketForClient);
                System.IO.StreamReader streamReader =
                new System.IO.StreamReader(networkStream);
                string theString = streamReader.ReadLine();
                MessageBox.Show(theString);  //message recieved how to send this back to local host           
                streamReader.Close();
                networkStream.Close();
                socketForClient.Close();
            //}
            */

	        try {

             
             //  Object dnsobject = new Dns();
               //String hostaddress = Dns.GetHostAddresses( hostName );
               Console.WriteLine(hostName + "\n");
               //Console.WriteLine(hostaddress + "\n");
	           //address = InetAddress.getByName(host);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Couldn't get internet address: Unknown address");
                
                //textArea.append("Couldn't get internet address: Unknown address"+newline);
            }
        }
    }
}